<?php

class table {
	public function __construct($table_id) {
		echo "<table id=\"$table_id\">";
	}

	public function css($header_class, $td_class) {
		$this->header_class = $header_class;
		$this->td_class = $td_class;
	}

	public function headers($names) {
		echo '<tr>';
		foreach($names as $name => $width) {
			echo "<td class=\"$this->header_class\" width=\"$width\">";
			echo $name;
			echo "</td>";
		}
		echo '</tr>';
	}
	
	public function columns($columns) {
		$this->columns = $columns;
	}

	public function query($sql) {
		$result = mysql_query($sql);
		while($row = mysql_fetch_assoc($result)) {
			echo '<tr>';
			foreach($this->columns as $column) {
				if($row[$column] == NULL) {
					$row[$column] = 'Active';
				}
				if(strlen($row[$column]) > 45) {
					$row[$column] = substr_replace($row[$column], '..', 45, (strlen($row[$column])));
				}
				echo "<td class=\"$this->td_class\">".$row[$column]."</td>";
			}
			echo '</tr>';
		}	
	}

	public function theend() {
		echo '</table>';
	}
}

?>
